#include<iostream>
using namespace std;

#include<vector>
#include<queue>


bool arr[5001] = { 0 };


int changeNumber(string& n, string& m)
{
	int length1 = n.size();
	int number = 0;
	for (int i = 0; i < length1; i++)
	{
		if (n[i] != m[i])
		{
			number++;
		}
		if (number == 2)
		{
			return number;
		}
	}
	return number;
}


int ladderLength(string beginWord, string endWord, vector<string>& wordList) {

	queue<string> q;
	q.push(beginWord);

	int number = 0;

	while (q.size())
	{
		int sz = q.size();
		number++;

		for (int i = 0; i < sz; i++)
		{
			string CurWord = q.front();
			q.pop();

			for (int j = 0; j < wordList.size(); j++)
			{
				if (!arr[j] && changeNumber(CurWord, wordList[j])==1)
				{
					if (wordList[j] == endWord)return number;

					arr[j] = 1;
					q.push(wordList[j]);
				}
			}
			
		}

	}

	return -1;
}


int main()
{

	return 0;
}